﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommandMgr.Repository;
using CommandMgr.Entities;

namespace CommandMgr.ServiceMgr
{
    public class CommandService
    {
        Repository.Repository repository = new Repository.Repository(new CommandContext());

        public List<Command> ListCommands()
        {
            return repository.ListCommands();
        }

        public List<string> ListCommandNames()
        {
            return repository.ListCommandNames();
        }

        public Command GetCommand(string Name)
        {
            return repository.GetCommand(Name);
        }

        public void AddCommand(string Name, string Descr)
        {
            repository.AddCommand(Name, Descr);
        }

        public void QueueCommand(string Name)
        {
            repository.AddCommandToQueue(Name);
        }

        public bool DequeueCommand(string Name)
        {
            return repository.RemoveCommandFromQueue(Name);
        }

        public void MarkCommandAsCompleted(string Name, string Response)
        {
            repository.UpdateCommandStatus(Name, Command.CommandStatus.completed, Response);
        }

        public void MarkCommandAsFailed(string Name, string Response)
        {
            repository.UpdateCommandStatus(Name, Command.CommandStatus.failed, Response);
        }

        public void MoveCommandToIdle(string Name)
        {
            repository.UpdateCommandStatus(Name, Command.CommandStatus.idle);
        }

        public Command.CommandStatus CheckStatus(string Name)
        {
            Command.CommandStatus status = Command.CommandStatus.notavailable;
            Command command = repository.GetCommand(Name);
            if (command != null)
                status = command.Status;
            return status;
        }

        public void DeleteCommand(string Name)
        {
            repository.DeleteCommand(Name);
        }

    }
}
